app.controller('BannerCtrl', ['$scope', '$timeout', '$http', '$compile', 'R', 'toaster', '$modal', '$rootScope', '$location', function($scope, $timeout, $http, $compile, R, toaster, $modal, $rootScope, $location) {
    $scope.currentpage = 20;
    $scope.totalCount = 0;

    $scope.query = {
        pageNo: 0,
        pageSize: $scope.currentpage
    }

    $scope.opened = [];
    $scope.open = function($event,index) {
        $event.preventDefault();
        $event.stopPropagation();
        $scope.opened[index] = true;
    };

    $scope.submit = function(){
        $scope.query.pageNo = 0;
        $scope.getItems();
    }

    $scope.rowCollectionPage = [];

    $scope.edit = function(row){
        $rootScope.setSgObj('BANNERONE', row);

        $location.url("/app/banner/one?type=" + row.type);
    }

    $scope.getItems = function(tableState, ctrl) {
        if (!$scope.stCtrl && ctrl) {
            $scope.stCtrl = ctrl;
        }

        if (!tableState && $scope.stCtrl) {
            $scope.stCtrl.pipe();
            return;
        }

        var pagination = tableState.pagination;

        $scope.query.pageNo = Math.ceil(pagination.start / $scope.currentpage);

        R.getAllBanner($scope.query).then(function(data) {
            $scope.rowCollectionPage = data.bizData;
        });
    };
}]);